package com.docted.design.pattern.proxy.dynamic.customer;

import com.docted.design.pattern.proxy.dynamic.jdk.Graduate;

import java.lang.reflect.Method;

/**
 * @author DoCted
 * @since v1.0 2018/3/11
 */
public class DocJobAgent implements DocInvocationHandler{


    private Graduate target;

    public Object getInstance(Graduate target) throws Exception {
        this.target = target;

        Class<?> clazz = target.getClass();

        return DocProxy.newProxyInstance(new DocClassLoader(), clazz.getInterfaces(), this);
    }



    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        System.out.println("I am your agent.");

        method.invoke(this.target, args);

        return null;
    }
}
